#include "email.h"

EMAIL*	email_new (MAIL*mail)
{
	EMAIL	*email;
	MIME	*m;
	GSList	*list;
	
	if (NULL == mail)
		return NULL;
		
	email = (EMAIL*)emalloc(sizeof(EMAIL));
	if (NULL == email) {
		return NULL;
	}
	
	email->head = mail->MailHead;
	
	list = mail->MailMime;	
	// 必须保证链表的第一项为text. 如果有html, 则第二项为html
	email->text = list->data;
	list = g_slist_next(list);
	m = list->data;
	if (m->stype == 'h') {
		email->html = m;
		email->attach = list->next;	
	}else{
		email->html = NULL;
		email->attach = list;
	}	
	
	return email;
}

void	email_delete (EMAIL *email)
{
	if (NULL == email)
		efree (email);
}

